<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperReference}">
    <resultMap id="BaseResultMap" type="${modelReference}">
        <#list columnList as data>
        <#if data.columnName=='ID' || data.columnName=='id'>
        <id column="ID" jdbcType="${data.columnType}" property="id"/>
        <#else>
        <result column="${data.columnName}" jdbcType="${data.columnType}" property="${data.varName}"/>
        </#if>
        </#list>
    </resultMap>

    <!--  字段列表  -->
    <sql id="base_column_list">
        <trim suffixOverrides=",">
            <#list columnList as data>
            ${data.columnName},
            </#list>
        </trim>
    </sql>

    <!--  批量新增  -->
    <#if databaseName == "MySQL">
    <insert id="batchInsert${tableInfo.className}" parameterType="java.util.List">
        INSERT INTO ${tableInfo.tableName}
        <trim prefix=" (" suffix=") " suffixOverrides=",">
            <#list columnList as data>${data.columnName},</#list>
        </trim>
        values
        <foreach collection="list" item="item" index="index" separator=",">
            <trim prefix=" (" suffix=") " suffixOverrides=",">
                <#list columnList as data><#noparse>#{</#noparse>item.${data.varName}<#noparse>}</#noparse>,</#list>
            </trim>
        </foreach>
    </insert>
    <#elseif databaseName == "Oracle" || databaseName == "DM DBMS">
    <insert id="batchInsert${tableInfo.className}" parameterType="java.util.List">
        INSERT ALL
        <foreach collection="list" item="item" index="index">
            INTO ${tableInfo.tableName}
            <trim prefix=" (" suffix=") " suffixOverrides=",">
                <#list columnList as data>${data.columnName},</#list>
            </trim>
            VALUES
            <trim prefix=" (" suffix=") " suffixOverrides=",">
                <#list columnList as data><#noparse>#{</#noparse>item.${data.varName}<#noparse>}</#noparse>,</#list>
            </trim>
        </foreach>
        SELECT 1 FROM DUAL
    </insert>
    <#else>
    </#if>

    <!-- 分页查询${tableInfo.tableComment} -->
    <select id="select${tableInfo.className}List" resultType="${basePackage}.vo.response.${tableInfo.className}ResponseVO">
        SELECT
        <include refid="base_column_list"/>
        FROM ${tableInfo.tableName}
        <where>
        <#list columnList as data>
            <#if data.excludeFromVO == true || data.varType != 'String' || data.varName == 'id'>
                <#continue>
            </#if>
            <if test="${data.varName} != null and ${data.varName} != ''">
                AND ${data.columnName} LIKE CONCAT('%',<#noparse>#{</#noparse>${data.varName}<#noparse>}</#noparse>,'%')
            </if>
        </#list>
        </where>
    </select>

</mapper>
